package com.ruoyi.excel.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.excel.domain.bo.AsyncImportExportTaskBo;
import com.ruoyi.excel.domain.vo.AsyncImportExportTaskVo;
import com.ruoyi.excel.service.IAsyncImportExportTaskService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.constraints.NotEmpty;
import java.util.Arrays;

/**
 * 异步导入导出Controller
 *
 * @Author: 付俊文
 * @Date: 2023/6/29 14:39
 */
@RestController
@RequestMapping("/system/excel")
public class AsyncImportExportController {
    @Resource
    private IAsyncImportExportTaskService asyncImportExportTaskService;

    /**
     * 查询异步excel任务中心列表
     */
    @SaCheckPermission("system:importExportTask:list")
    @GetMapping("/list")
    public TableDataInfo<AsyncImportExportTaskVo> list(AsyncImportExportTaskBo bo, PageQuery pageQuery) {
        return asyncImportExportTaskService.queryPageList(bo, pageQuery);
    }
    /**
     * 删除异步excel任务中心
     *
     * @param taskIds 主键串
     */
    @SaCheckPermission("system:importExportTask:remove")
    @Log(title = "异步excel任务中心", businessType = BusinessType.DELETE)
    @DeleteMapping("/{taskIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] taskIds) {
        return asyncImportExportTaskService.deleteWithValidByIds(Arrays.asList(taskIds)) ? R.ok("删除成功"):R.fail("删除失败");
    }
}

